package com.lc.qianrenshiye.activity;

import android.Manifest;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.lc.qianrenshiye.BaseActivity;
import com.lc.qianrenshiye.BaseApplication;
import com.lc.qianrenshiye.R;
import com.lc.qianrenshiye.conn.FeedbackPost;
import com.lc.qianrenshiye.dialog.WarnningDialog;
import com.lc.qianrenshiye.uitls.MyToast;
import com.lc.qianrenshiye.uitls.UtilPermission;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilApp;

/**
 * Created by Administrator on 2016/11/16.
 */
public class FeedbackActivity extends BaseActivity implements View.OnClickListener{

    @BoundView(R.id.feedback_content_et) private EditText feedback_content_et;
    @BoundView(R.id.feedback_submit_tv) private TextView feedback_submit_tv;
    @BoundView(R.id.feedback_call_service_tv) private TextView feedback_call_service_tv;

    private FeedbackPost feedbackPost = new FeedbackPost(new AsyCallBack<String>() {

        @Override
        public void onSuccess(String toast, int type, String s) throws Exception {

            MyToast.showToast(toast, context);

            finish();
        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            MyToast.showToast(toast, context);
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);

        String[] permission = { Manifest.permission.CALL_PHONE};
        UtilPermission.Permission(this, permission);


        setBackTrue();

        setTitleName(getString(R.string.feedback_title_text));


        feedback_submit_tv.setOnClickListener(this);
        feedback_call_service_tv.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.feedback_call_service_tv:


                new WarnningDialog(context, BaseApplication.BasePreferences.readServiceTel(), "取消", "呼叫") {
                    @Override
                    protected void onConfirm() {

                        UtilApp.call(context, BaseApplication.BasePreferences.readServiceTel());

                    }
                }.show();


                break;

            case R.id.feedback_submit_tv:

                String content = feedback_content_et.getText().toString().trim();

                if (TextUtils.isEmpty(content)) {

                    MyToast.showToast("请输入反馈内容", context);

                    return;
                }

                feedbackPost.uid = BaseApplication.BasePreferences.readUserId();
                feedbackPost.sid = BaseApplication.BasePreferences.readShopId();
                feedbackPost.content = content;

                feedbackPost.execute(this);

                break;

        }

    }
}
